<template>
  <div class="loginphone-page">
    <div class="headerBox">
      <van-nav-bar
      title="修改登录密码"
      left-arrow
      @click-left="onClickLeft"
    ></van-nav-bar>
    </div>
    <div class="input_box">
      <div class="samll_box">
        <i class="icon pass"></i>
        <input
          type="password"
          v-model="pass"
          placeholder="请输入密码（为6-16位数字、字母组成）"
          placeholder-style="color:#D6D5D5"
        />
      </div>
      <div class="samll_box">
        <i class="icon pass"></i>
        <input
          type="password"
          v-model="passTwo"
          placeholder="请输入确认密码"
          placeholder-style="color:#D6D5D5"
        />
      </div>
      <!-- <div class="text">*注：设置密码为6-16位数字、字母组成</div> -->
    </div>
    <div class="footers" v-show="isOriginHei">
      <span v-if="!typeTwo">提交</span>
      <span v-else class="sub" @click="submit">提交</span>
    </div>
  </div>
</template>

<script>
import positionBtn from "../positionBtn.js";
export default {
  mixins: [positionBtn],
  data() {
    return {
      typeTwo: false,
      username: "",
      iphone: "",
      code: "",
      pass: "",
      passTwo: "",
    };
  },
  watch: {
    passTwo(val) {
      if (val.length >= 4) {
        this.typeTwo = true;
      } else {
        this.typeTwo = false;
      }
    }
  },
  created() {
     console.log(this.$route.query)
     this.username = this.$route.query.username
     this.code = this.$route.query.code
     this.iphone = this.$route.query.tel
  },
  methods: {
    onClickLeft() {
      setTimeout(()=>{
        this.$router.go(-1);
      },200)
    },
    async submit() {
      let self= this
      if (!this.pass) {
        this.$toast("请输入新密码")
        return false
      } else if (!(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(this.pass))){
        this.$toast("请输入6-16位并包含数组和字母的密码")
        return false
      } else if (!this.passTwo) {
        this.$toast("请输入确认密码")
        return false
      } else if (this.passTwo != this.pass) {
        this.$toast("新密码与确认密码不一致")
        return false
      }
      let res = await this.$http.updateUserPass({
        tel: self.iphone,
        code: self.code,
        username: self.username,
        pass: self.pass
      })
      if (res) {
        this.$toast("修改密码成功，即将跳转...")
        setTimeout(()=>{
          this.$router.push({name: 'myCenter'})
        },2000)
        
      }
    }
  },
};
</script>

<style scoped>
.loginphone-page {
  background: #fff;
  height: 100vh;
}
.input_box {
  padding: 1rem 0.5rem;
}
.samll_box {
  height: 1rem;
  line-height: 1rem;
  border-bottom: 0.02rem solid #d6d5d5;
  margin-bottom: 0.4rem;
  position: relative;
}
.samll_box > input {
  height:100%;
  width: 5rem;
  border: none;
  font-size: 0.35rem;
}
.icon,
.clear {
  display: inline-block;
  width: 0.48rem;
  height: 0.48rem;
  position: relative;
  top: 0.1rem;
  margin-right: 0.2rem;
}
.user {
  background: url("../../assets/img/login/icon_geren.png") no-repeat;
  background-size: 100% 100%;
}
.pass {
  background: url("../../assets/img/login/icon_mima.png") no-repeat;
  background-size: 100% 100%;
}
.clear {
  background: url("../../assets/img/login/icon_shanch.png") no-repeat;
  background-size: 100% 100%;
}
.iphone {
  background: url("../../assets/img/login/icon_dianhua.png") no-repeat;
  background-size: 100% 100%;
}
.yan {
  background: url("../../assets/img/login/icon_yanzheng.png") no-repeat;
  background-size: 100% 100%;
}
.hy_code {
  display: inline-block;
  position: absolute;
  width: 1.88rem;
  height: 0.61rem;
  text-align: center;
  line-height: 0.61rem;
  color: #00c8e7;
  border-radius: 0.3rem;
  border: 0.02rem solid #00c8e7;
  top: 0.06rem;
  right: 0;
}
.forget {
  float: right;
  font-size: 0.29rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #000000;
}
.footers {
  width: 100%;
  position: fixed;
  padding: 0 0.5rem;
  bottom: 2.2rem;
}
.footers > span {
  width: 100%;
  display: inline-block;
  height: 0.94rem;
  background: #00c8e7;
  line-height: 0.94rem;
  text-align: center;
  color: #fff;
  border-radius: 0.47rem;
  font-size: 0.34rem;
  opacity: 0.4;
}
.footers span.sub {
  opacity: 1;
}
</style>
